<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增仪器信息')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-information-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">编号</label>
                <div class="col-sm-8">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">名称</label>
                <div class="col-sm-8">
                    <input name="deviceName" class="form-control" type="text" placeholder="请输入名称">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">创建人</label>
                <div class="col-sm-8">
                    <input name="createPerson" class="form-control" type="text" th:value="${@permission.getPrincipalProperty('userName')}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">部门:</label>
                <div class="col-sm-9">
                    <select class="form-control" id="deptIdList" name="deptId">
                        <option value="">请选择部门</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">创建时间:</label>
                <div class="col-sm-8">
                    <input name="createTime" class="form-control" type="text" th:value="${#dates.format(new java.util.Date(),'yyyy-MM-dd HH:mm:ss')}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">型号规格:</label>
                <div class="col-sm-8">
                    <input name="type" class="form-control" type="text" placeholder="请输入型号规格">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">主要技术指标:</label>
                <div class="col-sm-8">
                    <input name="mainAim" class="form-control" type="text" placeholder="请输入">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">检定有效期:</label>
                <div class="col-sm-8">
                    <input name="valid" class="form-control" type="text" placeholder="请输入">
                    <span>(单位:天)</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">存放位置:</label>
                <div class="col-sm-8">
                    <input name="savePosition" class="form-control" type="text" placeholder="请输入">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">仪器状态:</label>
                <div class="col-sm-8">
                    <select class="form-control" name="deviceStatus">
                        <option value="0">正常(默认)</option>
                        <option value="1">报废</option>
                        <option value="2">维修</option>
                        <option value="3">无效</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">附件:</label>
                <div class="col-sm-8">
                    <input type="hidden" name="file">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="file" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注 备注：</label>
                <div class="col-sm-8">
                    <textarea name="text" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "device/information"
        $("#form-information-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-information-add').serialize());
            }
        }

        $(".file-upload").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
    </script>
    <script th:inline="javascript">
        // 获取部门列表
        $(document).ready(function(){
            $.ajax({
                url: prefix + '/getDeptList',
                type: 'GET',
                dataType: 'json',
                success:function (response){
                    //获取用户列表填充到下拉框中
                    var userList = response.rows;
                    var selectElement = $('#deptIdList');
                    $.each(userList,function(index,user){
                        selectElement.append($('<option>',{
                            value: user.deptId,
                            text: user.deptName
                        }));
                    });
                },
                error: function(xhr,status,error){
                    console.error('错误',error)
                }
            })
        })
    </script>
</body>
</html>